<template>
  <div class="movie-container">
    <!-- 分类标题 -->
    <div class="category-header">
      <span class="category-title">电影</span>
      <a href="#" class="more-link">更多</a>
    </div>

    <!-- 电影列表 -->
    <div class="movie-grid">
      <div v-for="(movie, index) in movies" :key="index" class="movie-item">
        <div class="poster-container">

          <!-- 新增标签容器 -->
          <div class="image-labels">
            <span class="year-label">{{ movie.year }}</span>
            <span class="category-label">{{ movie.category }}</span>
          </div>

          <!-- 新增播放按钮 -->
          <div class="play-button" @click.stop="goToDetail(movie.movieId)">
            <el-icon :size="40">
              <VideoPlay />
            </el-icon>
          </div>

          <!-- 海报 -->
          <img :src="movie.poster" class="poster-image" alt="电影海报">

          <!-- 抽屉 -->
          <div class="info-drawer">
            <div class="movie-title-drawer">{{ movie.title }}</div>
            <div class="movie-actors">
              <span v-for="(actor, actorIndex) in movie.actors" :key="actorIndex" class="actor">{{ actor }}</span>
            </div>
            <div class="movie-description">{{ movie.description }}</div>
          </div>

        </div>

        <!--底部标题和剧集-->
        <div class="movie-info">
          <div class="movie-title">{{ movie.title }}</div>
          <div class="movie-video">{{ movie.video }}</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { useRouter } from 'vue-router'
import { VideoPlay } from '@element-plus/icons-vue'

const router = useRouter()


const movies = [
  {
    movieId:1,
    poster: "https://dummyimage.com/300x450/ccc/000",
    title: "异变狼人",
    video: "更新至11集",
    year: "2023",
    category: "动作惊悚",
    actors: ["弗兰·克兰兹第三方第三方胜多负少", "卡特·詹金斯", "伊芬·谢尔顿"],
    description: "两名科学家试图阻止一种突变，这种突变在前一年被超级月亮触摸后将人变成狼人。"
  },
  {
    movieId:1,
    poster: "https://dummyimage.com/300x450/ccc/000",
    title: "异变狼人",
    video: "更新至11集",
    year: "2023",
    category: "动作惊悚",
    actors: ["弗兰·克兰兹", "卡特·詹金斯", "伊芬·谢尔顿"],
    description: "两名科学家试图阻止一种突变，这种突变在前一年被超级月亮触摸后将人变成狼人。"
  },
  {
    movieId:1,
    poster: "https://dummyimage.com/300x450/ccc/000",
    title: "异变狼人",
    video: "更新至11集",
    year: "2023",
    category: "动作惊悚",
    actors: ["克兰兹", "卡詹金斯", "伊芬·谢尔顿"],
    description: "两名科学家试图阻止一种突变，这种突变在前一年被超级月亮触摸后将人变成狼人。"
  },
  // 更多电影数据...
];

const goToDetail = (movieId) => {
  router.push(`movies/detail/${movieId}`)
}

</script>

<style scoped>
.movie-container {
  padding: 20px;
  background-color: #e6eaef;
  color: black;
}

.category-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  padding: 0 40px;
}

.category-title {
  font-size: 24px;
  font-weight: 600;
}

.more-link {
  color: black;
  text-decoration: none;/* 移除下划线 */
  font-size: 14px;
  transition: color 0.3s; /* 添加颜色变化的过渡效果 */
}

.more-link:hover {
  color: deepskyblue;
}

.movie-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); /*表示每列的最小宽度为 200px，最大宽度为 1fr（即平分剩余空间）*/
  gap: 20px;
  padding: 0 40px;
}

.movie-item {
  position: relative;
  transition: transform 0.3s;
}

.movie-item:hover {
  transform: scale(1.05);
  z-index: 1;
}

.poster-container {
  position: relative;
  padding-top: 150%;
  border-radius: 4px;
  overflow: hidden;
}

.poster-image {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.movie-info {
  margin-top: 12px;
}

.movie-title {
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.movie-video {
  font-size: 12px;
  color: #a3a3a3;
  margin-top: 4px;
}

.poster-container {
  position: relative;
  padding-top: 150%;
  border-radius: 4px;
  overflow: hidden;
  cursor: pointer;
  transition: all 0.3s;
}

.info-drawer {
  position: absolute;
  bottom: -100%;/* 初始完全隐藏 */
  left: 0;
  right: 0;
  height: 46%;
  background: white;
  padding: 12px;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  backdrop-filter: blur(2px);
}

.poster-container:hover .info-drawer {
  bottom: 0;
}

.movie-title-drawer {
  color: black;
  font-size: 1.2em;
  font-weight: 600;
  margin-bottom: 8px;
}

.movie-actors {
  display: flex;
  gap: 8px;
  overflow: hidden;
  margin-bottom: 10px;
}

.actor {
  font-size: 0.8em;
  color: gray;
  padding: 2px 6px;
  background: #e6eaef;
  border-radius: 3px;
  max-width: 50px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex-shrink: 0;
}

.movie-description {
  font-size: 0.7em;
  color: #a3a3a3;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* 优化原有悬停效果 */
.movie-item:hover .poster-image {
  transform: scale(1.05);
}

/* 图片添加年份，类别标签*/
/* 新增标签样式 */
.image-labels {
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 1;
  display: flex;
  flex-direction: row-reverse;
  gap: 6px;
}

.year-label,
.category-label {
  font-size: 12px;
  padding: 4px 8px;
  border-radius: 3px;
  background: lightskyblue;
  color: white;
  backdrop-filter: blur(2px);
  max-width: 80px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.category-label {
  background: deepskyblue;
}

/* 调整海报容器定位 */
.poster-container {
  position: relative;
  padding-top: 150%;
  overflow: hidden;
  border-radius: 4px;
}

/* 保证标签在悬停时可见 */
.movie-item:hover .image-labels {
  z-index: 3; /* 高于抽屉的z-index */
}

/* 新增播放按钮样式 */
.play-button {
  position: absolute;
  top: 30%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 2;
  width: 30px;
  height: 30px;
  /*background: rgba(0, 0, 0, 0.7);*/
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0;
  transition: all 0.3s ease;
}

.play-button .el-icon {
  color: dodgerblue;
  /*margin-left: 4px; !* 调整播放图标位置 *!*/
}

.poster-container:hover .play-button {
  opacity: 1;
  background: #79a2c5;
  transform: translate(-50%, -50%) scale(1.1);
}

/* 调整标签层级 */
.image-labels {
  z-index: 3; /* 保证标签在播放按钮上方 */
}
</style>

